#!/usr/bin/env python 

import inkex
import simplestyle, sys
import andengineutils

class AndEngine(inkex.Effect):
    def __init__(self):
        """
        Constructor.
        Defines the "--what" option of a script.
        """
        # Call the base class constructor.
        inkex.Effect.__init__(self)
        
        # Define string option "--what" with "-w" shortcut and default value "World".
        self.OptionParser.add_option("--physic", action="store", type="inkbool", dest="physic", default=False, help="physic")
        self.OptionParser.add_option("--density", action="store", type="float", dest="density", default=0, help="Density")
        self.OptionParser.add_option("--elastic", action="store", type="float", dest="elastic", default=0, help="Elastic")
        self.OptionParser.add_option("--friction", action="store", type="float", dest="friction", default=0, help="Friction")
        self.OptionParser.add_option("--bodytype", action="store", type="int", dest="bodytype", default=0, help="Bodytype")
        
        
    def effect(self):
        for id, node in self.selected.iteritems():
            if(self.options.physic):
                andengineutils.creatOrDelete("andengine-physic", node, self.options.physic, False)
                andengineutils.creatOrDelete("andengine-density", node, self.options.density, 0)
                andengineutils.creatOrDelete("andengine-elasticity", node, self.options.elastic, 0)
                andengineutils.creatOrDelete("andengine-friction", node, self.options.friction, 0)
                andengineutils.creatOrDelete("andengine-bodytype", node, self.options.bodytype, 0)
            else:
                andengineutils.delAttribute("andengine-physic", node)
                andengineutils.delAttribute("andengine-density", node)
                andengineutils.delAttribute("andengine-elasticity", node)
                andengineutils.delAttribute("andengine-friction", node)
                andengineutils.delAttribute("andengine-bodytype", node)
            
        
if __name__ == '__main__':
    e = AndEngine()
    e.affect()